package com.ruoyi.web.controller.production.carton;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.carton.CartonType;
import com.ruoyi.production.service.carton.ICartonTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 纸箱类型Controller
 *
 * @author ruoyi
 * @date 2021-07-08
 */
@RestController
@RequestMapping("/system/cartonType")
public class CartonTypeController extends BaseController
{
    @Autowired
    private ICartonTypeService cartonTypeService;

    /**
     * 查询纸箱类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(CartonType cartonType)
    {
        startPage();
        List<CartonType> list = cartonTypeService.selectCartonTypeList(cartonType);
        return getDataTable(list);
    }

    /**
     * 导出纸箱类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "纸箱类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CartonType cartonType)
    {
        List<CartonType> list = cartonTypeService.selectCartonTypeList(cartonType);
        ExcelUtil<CartonType> util = new ExcelUtil<CartonType>(CartonType.class);
        return util.exportExcel(list, "纸箱类型数据");
    }

    /**
     * 获取纸箱类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{cartonTypeId}")
    public AjaxResult getInfo(@PathVariable("cartonTypeId") Long cartonTypeId)
    {
        return AjaxResult.success(cartonTypeService.selectCartonTypeById(cartonTypeId));
    }

    /**
     * 新增纸箱类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "纸箱类型", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody CartonType cartonType)
    {
        return toAjax(cartonTypeService.insertCartonType(cartonType));
    }

    /**
     * 修改纸箱类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "纸箱类型", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody CartonType cartonType)
    {
        return toAjax(cartonTypeService.updateCartonType(cartonType));
    }

    /**
     * 删除纸箱类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "纸箱类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cartonTypeIds}")
    public AjaxResult remove(@PathVariable Long[] cartonTypeIds)
    {
        return toAjax(cartonTypeService.deleteCartonTypeByIds(cartonTypeIds));
    }
}
